home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / XPK / Source / examples / XpkSAS.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-15  |  1.7 KB  |  76 lines

  1. /* XPK - General XPK file-to-file packer/unpacker */
  2. /* This is the version to be compiled with SAS/C  */
  3.  
  4. #include <proto/exec.h>
  5. #include <proto/dos.h>
  6. #include <pragma/xpkmaster_lib.h>
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10.  
  11. struct Library *XpkBase;
  12. char errbuf[XPKERRMSGSIZE + 1];    /* +1 to make room for '\n'        */
  13.  
  14. /* disable lattice CTRL-C handling */
  15. int chkabort (void)
  16. {
  17.   return 0;
  18. }
  19.  
  20. long __asm __saveds chunkfunc(register __a1 struct XpkProgress *prog)
  21. {
  22.   printf ("\r%4s: %-9s %-12s (%6d bytes, %3d%% done, %2d%% CF, %6d cps) ",
  23.     prog->xp_PackerName, prog->xp_Activity, prog->xp_FileName,
  24.     prog->xp_ULen, prog->xp_Done, prog->xp_CF, prog->xp_Speed);
  25.   if (prog->xp_Type == XPKPROG_END)
  26.     printf ("\n");
  27.  
  28.   return (long) SetSignal (0, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C;
  29. }
  30. struct Hook chunkhook =
  31. { {0}, chunkfunc};
  32.  
  33. struct TagItem tags[]=
  34. {
  35.   XPK_InName, (long) NULL,
  36.   XPK_OutName, (long) NULL,
  37.   XPK_Ignore, (long) 0,
  38.   XPK_NoClobber, (long) TRUE,
  39.   XPK_GetError, (long) errbuf,
  40.   XPK_ChunkHook, (long) &chunkhook,
  41.   TAG_DONE};
  42.  
  43. void end (char *text)
  44. {
  45.   if (text)
  46.     Write (Output (), text, strlen (text));
  47.   if (XpkBase)
  48.     CloseLibrary (XpkBase);
  49.   exit (text ? 10 : 0);
  50. }
  51.  
  52. void main (int argc, char *argv[])
  53. {
  54.   int res;
  55.  
  56.   if (!(XpkBase = OpenLibrary (XPKNAME, 0)))
  57.     end ("Cannot open " XPKNAME "\n");
  58.  
  59.   if ((argc < 3) || (argc > 4))
  60.     end ("Usage: XPK [<method>] <infile> <outfile>\n");
  61.  
  62.   tags[0].ti_Data = (long) argv[argc - 2];    /* First try to decompress... */
  63.   tags[1].ti_Data = (long) argv[argc - 1];
  64.   if (argc == 3)
  65.     res = XpkUnpack (tags);
  66.   else {
  67.     tags[2].ti_Tag = XPK_PackMethod;
  68.     tags[2].ti_Data = (long) argv[1];
  69.     res = XpkPack (tags);
  70.   }
  71.   if (res)
  72.     end (strcat (errbuf, "\n"));
  73.  
  74.   end (NULL);
  75. }
  76.